package com.xayy.health.mgt.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.exceptions.ExceptionUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpStatus;
import cn.hutool.http.Method;
import cn.kawins.base.result.CheckResult;
import cn.kawins.base.utils.BeanUtil;
import cn.kawins.base.utils.CollUtil;
import cn.kawins.base.utils.HttpUtil;
import cn.kawins.mybatis.base.BaseServiceImpl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.xayy.health.core.config.param.DsParam;
import com.xayy.health.core.constant.HealthManagerConstant;
import com.xayy.health.core.enums.AbnormalTypeEnum;
import com.xayy.health.core.enums.ModuleEnum;
import com.xayy.health.core.enums.TaskStatusEnum;
import com.xayy.health.core.exception.HealthException;
import com.xayy.health.mgt.mapper.AppTlmCheckAnomalRsltMapper;
import com.xayy.health.mgt.mapper.DataQualityMapper;
import com.xayy.health.mgt.mapper.SatelliteNodeMapper;
import com.xayy.health.mgt.model.*;
import com.xayy.health.mgt.model.dto.DataFeatureDto;
import com.xayy.health.mgt.model.dto.DataQualityDto;
import com.xayy.health.mgt.model.dto.TelemetryDto;
import com.xayy.health.mgt.model.vo.*;
import com.xayy.health.mgt.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.net.UnknownHostException;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author zhangxa
 */
@Service
public class DataQualityServiceImpl extends BaseServiceImpl<DataQuality> implements DataQualityService {

    @Autowired
    private DataQualityMapper dataQualityMapper;
    @Autowired
    private TaskChildInfoService taskChildInfoService;
    @Autowired
    private DataFeatureService dataFeatureService;
    @Autowired
    private DataMiddleService dataMiddleService;
    @Autowired
    private SatelliteNodeService satelliteNodeService;
    @Autowired
    private DsParam dsParam;
    @Autowired
    private DataFeatureService telemetryDataService;
    @Autowired
    private AppTlmCheckAnomalRsltMapper appTlmCheckAnomalRsltMapper;
    @Autowired
    private DataQualityService dataQualityService;

    @Autowired
    private SatelliteNodeMapper satelliteNodeMapper;

    @Autowired
    private FaultReportService faultReportService;

    /**
     * 根据类型查询对应的分页数据
     *
     * @param dataQualityDto 入参
     * @return CheckResult<Object>
     */
    public CheckResult<Object> getPageListByAbnormalType(DataQualityDto dataQualityDto) {
        DataSourceVo anomalData = new DataSourceVo();
        anomalData.setDbKey("HOLOGRES");
        CheckResult<Object> checkResult = null;
        //1.中断2.丢帧3.复诊4.识别字
        if (dataQualityDto.getAbnormalType() == HealthManagerConstant.ZD_TYPE) {

            if (StrUtil.isNotEmpty(dataQualityDto.getStartTime()) && StrUtil.isNotEmpty(dataQualityDto.getEndTime())) {
                anomalData.setSql("select * from app_tlm_check_frameloss_rslt where anomal_cd = '2' and satellite_code  = '" + dataQualityDto.getSatelliteCode() + "' and Data_Time between '" + dataQualityDto.getStartTime() + "' and '" + dataQualityDto.getEndTime() + "' limit " + dataQualityDto.getSize() + " offset " + (dataQualityDto.getPage() - 1) * dataQualityDto.getSize());
            } else {
                anomalData.setSql("select * from app_tlm_check_frameloss_rslt where anomal_cd = '2' and satellite_code  = '" + dataQualityDto.getSatelliteCode() + "' limit " + dataQualityDto.getSize() + " offset " + (dataQualityDto.getPage() - 1) * dataQualityDto.getSize());
            }
            checkResult = dataQualityService.excuteRunSql(anomalData);
        } else if (dataQualityDto.getAbnormalType() == HealthManagerConstant.DZ_TYPE) {
            if (StrUtil.isNotEmpty(dataQualityDto.getStartTime()) && StrUtil.isNotEmpty(dataQualityDto.getEndTime())) {
                anomalData.setSql("select * from app_tlm_check_frameloss_rslt where anomal_cd = '3' and satellite_code  = '" + dataQualityDto.getSatelliteCode() + "' and Data_Time between '" + dataQualityDto.getStartTime() + "' and '" + dataQualityDto.getEndTime() + "' limit " + dataQualityDto.getSize() + " offset " + (dataQualityDto.getPage() - 1) * dataQualityDto.getSize());
            } else {
                anomalData.setSql("select * from app_tlm_check_frameloss_rslt where anomal_cd = '3' and satellite_code  = '" + dataQualityDto.getSatelliteCode() + "' limit " + dataQualityDto.getSize() + " offset " + (dataQualityDto.getPage() - 1) * dataQualityDto.getSize());
            }

            checkResult = dataQualityService.excuteRunSql(anomalData);
        } else if (dataQualityDto.getAbnormalType() == HealthManagerConstant.FZ_TYPE) {
            if (StrUtil.isNotEmpty(dataQualityDto.getStartTime()) && StrUtil.isNotEmpty(dataQualityDto.getEndTime())) {
                anomalData.setSql("select * from app_tlm_check_anomal_rslt where anomal_cd = '4' and satellite_code  = '" + dataQualityDto.getSatelliteCode() + "' and Data_Time between '" + dataQualityDto.getStartTime() + "' and '" + dataQualityDto.getEndTime() + "' limit " + dataQualityDto.getSize() + " offset " + (dataQualityDto.getPage() - 1) * dataQualityDto.getSize());
            } else {
                anomalData.setSql("select * from app_tlm_check_anomal_rslt where anomal_cd = '4' and satellite_code  = '" + dataQualityDto.getSatelliteCode() + "' limit " + dataQualityDto.getSize() + " offset " + (dataQualityDto.getPage() - 1) * dataQualityDto.getSize());
            }

            checkResult = dataQualityService.excuteRunSql(anomalData);
        } else if (dataQualityDto.getAbnormalType() == HealthManagerConstant.SBZ_TYPE) {
            if (StrUtil.isNotEmpty(dataQualityDto.getStartTime()) && StrUtil.isNotEmpty(dataQualityDto.getEndTime())) {
                anomalData.setSql("select * from app_tlm_check_anomal_rslt where anomal_cd = '1' and satellite_code  = '" + dataQualityDto.getSatelliteCode() + "' and Data_Time between '" + dataQualityDto.getStartTime() + "' and '" + dataQualityDto.getEndTime() + "' limit " + dataQualityDto.getSize() + " offset " + (dataQualityDto.getPage() - 1) * dataQualityDto.getSize());
            } else {
                anomalData.setSql("select * from app_tlm_check_anomal_rslt where anomal_cd = '1' and satellite_code  = '" + dataQualityDto.getSatelliteCode() + "' limit " + dataQualityDto.getSize() + " offset " + (dataQualityDto.getPage() - 1) * dataQualityDto.getSize());
            }
            checkResult = dataQualityService.excuteRunSql(anomalData);
        }
        return checkResult;
    }

    /**
     * 质量分析信息集合分页信息
     *
     * @param dataQualityDto 入参信息
     * @return 分页信息
     */
    @Override
    public PageInfo<QualityVo> pageList(DataQualityDto dataQualityDto) {
        if (StrUtil.isNotEmpty(dataQualityDto.getSatelliteCode())) {
            CheckResult<Object> checkResult = getPageListByAbnormalType(dataQualityDto);
            Map data = (Map) checkResult.getData();
            String commonDataString = JSON.toJSONString(data.get("data"));
            if (!HealthManagerConstant.NULL_STR.equals(commonDataString)) {
                List<QualityVo> list = JSONObject.parseArray(commonDataString, QualityVo.class);
                PageInfo<QualityVo> pageInfo = new PageInfo<>();
                pageInfo.setList(list);
                ReportVo reportVo = BeanUtil.copyBean(dataQualityDto, ReportVo.class);
                //处理类型标识
                String satelliteId =null;
                if(!CollectionUtil.isEmpty(list)){
                    QualityVo vo=list.get(0);
                    String liteCode = vo.getSatelliteCode();
                    String satelliteNewId = satelliteNodeMapper.getSatelliteCode(liteCode);
                    if (null != satelliteNewId) {
                        satelliteId=satelliteNewId;
                    }
                }
                for (QualityVo qualityVo : list) {
                    if (dataQualityDto.getAbnormalType() == 1) {
                        qualityVo.setAnomalCd(AbnormalTypeEnum.valueof(1));
                    } else if (dataQualityDto.getAbnormalType() == 2) {
                        qualityVo.setAnomalCd(AbnormalTypeEnum.valueof(2));
                    } else if (dataQualityDto.getAbnormalType() == 3) {
                        qualityVo.setAnomalCd(AbnormalTypeEnum.valueof(3));
                    } else if (dataQualityDto.getAbnormalType() == 4) {
                        qualityVo.setAnomalCd(AbnormalTypeEnum.valueof(4));
                    }
                    qualityVo.setSatelliteId(satelliteId);
                }

                if (dataQualityDto.getAbnormalType() == HealthManagerConstant.ZD_TYPE) {
                    Integer zdTotal1 = countMethod("app_tlm_check_frameloss_rslt", "zdtotal", reportVo, "2");
                    pageInfo.setTotal(zdTotal1);
                } else if (dataQualityDto.getAbnormalType() == HealthManagerConstant.DZ_TYPE) {
                    Integer dzTotal1 = countMethod("app_tlm_check_frameloss_rslt", "dztotal", reportVo, "3");
                    pageInfo.setTotal(dzTotal1);
                } else if (dataQualityDto.getAbnormalType() == HealthManagerConstant.FZ_TYPE) {
                    Integer fzTotal1 = countMethod("app_tlm_check_anomal_rslt", "fztotal", reportVo, "4");
                    pageInfo.setTotal(fzTotal1);
                } else if (dataQualityDto.getAbnormalType() == HealthManagerConstant.SBZ_TYPE) {
                    Integer sbzTotal1 = countMethod("app_tlm_check_anomal_rslt", "sbztotal", reportVo, "1");
                    pageInfo.setTotal(sbzTotal1);
                }

                if (CollectionUtil.isEmpty(list)) {
                    return new PageInfo(new ArrayList());
                } else {
                    return pageInfo;
                }
            } else {
                return new PageInfo(new ArrayList());
            }
        } else {
            return new PageInfo(new ArrayList());
        }
    }

    /**
     * 查询质量分析信息集合
     *
     * @param dataQualityDto 集合信息
     * @return 结果日志
     */
    @Override
    public List<DataQuality> selectList(DataQualityDto dataQualityDto) {
        List<DataQuality> dataQualities = dataQualityMapper.getList(dataQualityDto);
        dataQualities.forEach((e) -> e.setAbnormalTypeName(AbnormalTypeEnum.valueof(e.getAbnormalType())));
        return dataQualities;
    }

    /**
     * 异步线程池执行任务
     *
     * @param taskChildInfo 子任务信息 任务信息
     */
    @Override
    public void asyncExcuteTask(TaskChildInfo taskChildInfo) throws UnknownHostException {
        try {
            String[] split = taskChildInfo.getParams().split(",");
            if (ObjectUtil.isEmpty(split)) {
                return;
            }
            for (String param : split) {
                // 获取遥测参数
                DataFeatureDto dataFeatureDto = new DataFeatureDto();
                dataFeatureDto.setSatelliteCode(taskChildInfo.getSatelliteCode());
                dataFeatureDto.setParamCode(param);
                dataFeatureDto.setSatelliteCode(taskChildInfo.getSatelliteCode());
                dataFeatureDto.setStartTime(taskChildInfo.getStartTime());
                dataFeatureDto.setEndTime(taskChildInfo.getEndTime());
                // 原始数据
                List<TelemetryData> telemetryDataList = satelliteNodeService.getYcList(dataFeatureDto);
                if (CollectionUtil.isEmpty(telemetryDataList)) {
                    taskChildInfo.setDataSituation("无");
                    taskChildInfoService.updateByIdSelective(taskChildInfo);
                    continue;
                }
                log.info("遥测参数查询：{}", dataFeatureDto);
                // 调用算法
                TelemetryDto telemetryDto = TelemetryDto.builder().taskRecordId(1L)
                        .paramCodes(Convert.toStrArray(param)).telemetryDataList(telemetryDataList)
                        .tyTag(taskChildInfo.getTyTag()).tcTag(taskChildInfo.getTcTag()).phTag(taskChildInfo.getPhTag())
                        .startTime(taskChildInfo.getStartTime()).endTime(taskChildInfo.getEndTime()).build();

                boolean hasNullValue = telemetryDto.isHasNullValue();
                //判断是否存在空值
                for (TelemetryData data : telemetryDataList) {
                    if (!hasNullValue && StringUtils.isEmpty(data.getValue())) {
                        telemetryDto.setHasNullValue(true);
                    }
                }

                List<Object> peredatas = null;
                try {
                    peredatas = dataFeatureService.predata(telemetryDto);
                } catch (Exception e) {
                    log.error("数据处理调用算法出错....taskId={}",taskChildInfo.getTaskId());
                    taskChildInfo.setStatus(TaskStatusEnum.ABNORMAL.getCode());
                    taskChildInfo.setMsg(e.getMessage());
                    faultReportService.faultReport(ModuleEnum.SJCL.getCode(), ModuleEnum.SJCL.getMsg(),"数据处理调用算法出错","数据处理调用算法出错");
                    taskChildInfoService.updateByIdSelective(taskChildInfo);
                    return;
                }
                if(!CollectionUtils.isEmpty(peredatas)){
                peredatas.forEach((o) -> {
                    Map<String, List<Map<String, List<Map<String, Object>>>>> listMap =
                            (Map<String, List<Map<String, List<Map<String, Object>>>>>) o;
                    List<Map<String, List<Map<String, Object>>>> dataList = listMap.get(param);
                    dataList.forEach((m -> {
                        if (StrUtil.isNotEmpty(taskChildInfo.getPhTag()) && StrUtil.isNotEmpty(taskChildInfo.getTcTag()) && StrUtil.isNotEmpty(taskChildInfo.getTyTag())) {
                            getTcData(m, taskChildInfo, param);
                            getTiyeValue(m, taskChildInfo, param);
                            getPhData(m, taskChildInfo, param);
                        } else if (StrUtil.isNotEmpty(taskChildInfo.getPhTag()) && StrUtil.isEmpty(taskChildInfo.getTcTag()) && StrUtil.isEmpty(taskChildInfo.getTyTag())) {
                            getPhData(m, taskChildInfo, param);
                        } else if (StrUtil.isNotEmpty(taskChildInfo.getTcTag()) && StrUtil.isEmpty(taskChildInfo.getPhTag()) && StrUtil.isEmpty(taskChildInfo.getTyTag())) {
                            getTcData(m, taskChildInfo, param);
                        } else if (StrUtil.isNotEmpty(taskChildInfo.getTyTag()) && StrUtil.isEmpty(taskChildInfo.getTcTag()) && StrUtil.isEmpty(taskChildInfo.getPhTag())) {
                            getTiyeValue(m, taskChildInfo, param);
                        } else if (StrUtil.isNotEmpty(taskChildInfo.getTyTag()) && StrUtil.isEmpty(taskChildInfo.getTcTag()) && StrUtil.isEmpty(taskChildInfo.getPhTag())) {
                            getTcData(m, taskChildInfo, param);
                            getTiyeValue(m, taskChildInfo, param);
                        } else if (StrUtil.isNotEmpty(taskChildInfo.getTyTag()) && StrUtil.isNotEmpty(taskChildInfo.getPhTag()) && StrUtil.isEmpty(taskChildInfo.getTcTag())) {
                            getTiyeValue(m, taskChildInfo, param);
                            getPhData(m, taskChildInfo, param);
                        } else if (StrUtil.isNotEmpty(taskChildInfo.getPhTag()) && StrUtil.isNotEmpty(taskChildInfo.getTcTag()) && StrUtil.isEmpty(taskChildInfo.getTyTag())) {
                            getTcData(m, taskChildInfo, param);
                            getPhData(m, taskChildInfo, param);
                        } else {
                            // 平滑数据填充
                            telemetryDataList.forEach(x -> x.setParentTaskId(taskChildInfo.getTaskId()));
                            dataFeatureService.insertPh(telemetryDataList);
                            taskChildInfo.setDataSituation("(" + telemetryDataList.get(0).getTime() + "," + telemetryDataList.get(telemetryDataList.size() - 1).getTime() + ")");
                        }
                        // 剔野值
                        List<Map<String, Object>> tiYeData = m.get("ty");
                        if (CollectionUtil.isNotEmpty(tiYeData)) {
                            ArrayList<TelemetryData> telemetryList = new ArrayList<>();
                            tiYeData.forEach(t -> {
                                String time = Convert.toStr(t.get("time"));
                                String value = Convert.toStr(t.get("value"));
                                TelemetryData telemetryData = TelemetryData.builder().time(time).value(value)
                                        .taskId(taskChildInfo.getId()).valueType("2")
                                        .sateCode(taskChildInfo.getSatelliteCode()).paramCode(param).build();
                                telemetryList.add(telemetryData);

                            });
                            dataFeatureService.insertTy(telemetryList);
                        }
                        // 填充值
                        List<Map<String, Object>> tianChongData = m.get("tc");
                        if (CollectionUtil.isNotEmpty(tianChongData)) {
                            ArrayList<TelemetryData> telemetryList = new ArrayList<>();
                            tianChongData.forEach(t -> {
                                String time = Convert.toStr(t.get("time"));
                                String value = Convert.toStr(t.get("data"));
                                TelemetryData telemetryData = TelemetryData.builder().time(time).value(value)
                                        .taskId(taskChildInfo.getId()).valueType("2")
                                        .sateCode(taskChildInfo.getSatelliteCode()).paramCode(param).build();
                                telemetryList.add(telemetryData);
                            });
                            dataFeatureService.insertTc(telemetryList);

                        }
                        // 中位数数据
                        List<Map<String, Object>> jzData = m.get("zjData");
                        if (CollectionUtil.isNotEmpty(jzData)) {
                            jzData.forEach(t -> {
                                // 将图表中位数入库
                                DataMiddle dataMiddle = new DataMiddle();
                                dataMiddle.setTaskId(taskChildInfo.getId());
                                dataMiddle.setParamCode(param);
                                dataMiddle.setSatelliteCode(taskChildInfo.getSatelliteCode());
                                dataMiddle.setMean(Convert.toDouble(t.get("mean")));
                                dataMiddle.setMedian(Convert.toDouble(t.get("median")));
                                dataMiddle.setQuantile(Convert.toStr(t.get("quantile")));
                                dataMiddle.setRangeValue(Convert.toDouble(t.get("rangeValue")));
                                dataMiddle.setVariance(Convert.toDouble(t.get("variance")));
                                dataMiddle.setStandardDeviation(Convert.toDouble(t.get("standardDeviation")));
                                dataMiddle.setMse(Convert.toDouble(t.get("mse")));
                                dataMiddle.setCreateTime(Convert.toStr(t.get("createTime")));
                                dataMiddle.setStartTime(taskChildInfo.getStartTime());
                                dataMiddle.setEndTime(taskChildInfo.getEndTime());
                                dataMiddleService.insert(dataMiddle);
                            });
                        }
                    }));
                });
            }

              }

            taskChildInfo.setStatus(TaskStatusEnum.DONE.getCode());
            taskChildInfoService.updateByIdSelective(taskChildInfo);
        } catch (Exception e) {
            taskChildInfo.setDataSituation("无");
            // 修改任务状态
            taskChildInfo.setStatus(TaskStatusEnum.ABNORMAL.getCode());
            taskChildInfoService.updateByIdSelective(taskChildInfo);
            faultReportService.faultReport(ModuleEnum.SJCL.getCode(), ModuleEnum.SJCL.getMsg(),"任务执行失败",ExceptionUtil.getMessage(e));
            log.error("任务:{} 执行失败! 异常信息:{}", taskChildInfo.getName(), ExceptionUtil.getMessage(e));
        }

    }

    /**
     * 剔野数据
     *
     * @param taskChildInfo 子任务信息
     * @param param         参数
     */
    public void getTiyeValue(Map<String, List<Map<String, Object>>> m, TaskChildInfo taskChildInfo, String
            param) {
        // 剔野数据
        List<Map<String, Object>> tyData = m.get("tyData");
        ArrayList<TelemetryData> telemetryList = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(tyData)) {
            taskChildInfo.setDataSituation("(" + tyData.get(0).get("time").toString() + "," + tyData.get(tyData.size() - 1).get("time").toString() + ")");
            tyData.forEach(t -> {
                String time = Convert.toStr(t.get("time"));
                String value = Convert.toStr(t.get("value"));
                TelemetryData telemetryData =
                        TelemetryData.builder().time(time).value(value).taskId(taskChildInfo.getId()).valueType("1")
                                .sateCode(taskChildInfo.getSatelliteCode()).paramCode(param).build();
                telemetryList.add(telemetryData);
            });
            taskChildInfoService.updateByIdSelective(taskChildInfo);
            dataFeatureService.insertTy(telemetryList);
            log.info("剔野数据插入完成................................................................");
        }
    }

    /**
     * 填充数据
     *
     * @param taskChildInfo 子任务信息
     * @param param         参数
     */
    public void getTcData(Map<String, List<Map<String, Object>>> m, TaskChildInfo taskChildInfo, String
            param) {
        // 填充数据
        List<Map<String, Object>> tcData = m.get("tcData");
        ArrayList<TelemetryData> telemetryList = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(tcData)) {
            taskChildInfo.setDataSituation("(" + tcData.get(0).get("time").toString() + "," + tcData.get(tcData.size() - 1).get("time").toString() + ")");
            tcData.forEach(t -> {
                String time = Convert.toStr(t.get("time"));
                String value = Convert.toStr(t.get("value"));
                TelemetryData telemetryData =
                        TelemetryData.builder().time(time).value(value).taskId(taskChildInfo.getId()).valueType("1")
                                .sateCode(taskChildInfo.getSatelliteCode()).paramCode(param).build();
                telemetryList.add(telemetryData);

            });
            taskChildInfoService.updateByIdSelective(taskChildInfo);
            dataFeatureService.insertTc(telemetryList);
            log.info("填充数据插入完成................................................................");
        }
    }

    /**
     * 平滑数据
     *
     * @param taskChildInfo 子任务信息
     * @param param         参数
     */
    public void getPhData(Map<String, List<Map<String, Object>>> m, TaskChildInfo taskChildInfo, String
            param) {
        // 平滑数据
        List<Map<String, Object>> phData = m.get("phData");
        ArrayList<TelemetryData> telemetryList = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(phData)) {
            taskChildInfo.setDataSituation("(" + phData.get(0).get("time").toString() + "," + phData.get(phData.size() - 1).get("time").toString() + ")");
            phData.forEach(t -> {
                String time = Convert.toStr(t.get("time"));
                String value = Convert.toStr(t.get("doubleValue"));
                TelemetryData telemetryData = TelemetryData.builder().time(time).value(value)
                        .parentTaskId(taskChildInfo.getTaskId()).taskId(taskChildInfo.getId()).valueType("1")
                        .sateCode(taskChildInfo.getSatelliteCode()).paramCode(param).build();

                telemetryList.add(telemetryData);

            });
            taskChildInfoService.updateByIdSelective(taskChildInfo);
            dataFeatureService.insertPh(telemetryList);
            log.info("平滑数据插入完成................................................................");
        }
    }

    /**
     * 数据预处理手动剔野
     *
     * @param handWinkingVo 被剔野信息集合
     * @return 结果日志
     */
    @Override
    public CheckResult<Object> handWinking(HandWinkingVo handWinkingVo) {
        List<EchartVo> echartVos = handWinkingVo.getEchartVos();
        Long taskChildId = handWinkingVo.getTaskChildId();
        if (CollUtil.isNotEmpty(echartVos)) {
            List<String> times = new ArrayList<>();
            String sateCode = null;
            String paramCode = null;
            for (EchartVo echartVo : echartVos) {
                sateCode = echartVo.getSateCode();
                paramCode = echartVo.getParamCode();
                String time = echartVo.getTime();
                times.add(time);
            }
            dataQualityMapper.handWinking(times, sateCode, paramCode, taskChildId);

        }
        return CheckResult.success();
    }

    /**
     * 特征分析图表
     *
     * @param dataFeatureDto 质量分析入参
     * @return 结果日志
     */
    @Override
    public CheckResult<Object> getFeatureEcharts(DataFeatureDto dataFeatureDto) {
        //剔野后
        List<Map<String, Object>> tyBackDataList = CollUtil.newArrayList();
        //填充后
        List<Map<String, Object>> tcBackDataList = CollUtil.newArrayList();
        //平滑后
        List<Map<String, Object>> phBackDataList = CollUtil.newArrayList();
        //原始数据
        List<Map<String, Object>> ycDataList = CollUtil.newArrayList();
        //野值
        List<Map<String, Object>> yzDataList = CollUtil.newArrayList();
        //填充值
        List<Map<String, Object>> tcDataList = CollUtil.newArrayList();

        // 剔野后
        List<TelemetryData> tyList = telemetryDataService.getTyList(dataFeatureDto);
        if(!CollectionUtils.isEmpty(tyList)){
            tyList.stream().filter(item -> "2".equals(item.getValueType())).forEach(x -> x.setValue(null));
            List<TelemetryData> tyDateList = tyList.stream().sorted((o1, o2) -> {
                try {
                    DateTime date1 = DateUtil.parse(o1.getTime(), "yyyy-MM-dd HH:mm:ss.SSS");
                    DateTime date2 = DateUtil.parse(o2.getTime(), "yyyy-MM-dd HH:mm:ss.SSS");
                    return date1.compareTo(date2);
                } catch (Exception e) {
                    e.printStackTrace();
                    try {
                        faultReportService.faultReport(ModuleEnum.SJCL.getCode(), ModuleEnum.SHZD.getMsg(),"特征分析剔野异常","剔野调用算法异常");
                    } catch (UnknownHostException ex) {
                        throw new RuntimeException(ex);
                    }
                    return 0;
                }
            }).collect(Collectors.toList());
            if (CollUtil.isNotEmpty(tyDateList)) {
                tyDateList.forEach((x) -> {
                    Map<String, Object> map = new HashMap<>(2);
                    if (x.getTime().length() == HealthManagerConstant.TIME_TWENTY_TWO) {
                        map.put("time", x.getTime() + "0");
                    } else {
                        map.put("time", x.getTime());
                    }
                    DateTime date1 = DateUtil.parse(x.getTime(), "yyyy-MM-dd HH:mm:ss.SSS");
                    map.put("timestamp", date1.getTime());
                    map.put("value", x.getValue());
//                map.put("sateCode", x.getSateCode());
//                map.put("paramCode", x.getParamCode());
                    tyBackDataList.add(map);
                });
            }

        }

        // 填充后
        dataFeatureDto.setValueType("1");
        List<TelemetryData> tcList = telemetryDataService.getTcList(dataFeatureDto);
        if(!CollectionUtils.isEmpty(tcList)){
            List<TelemetryData> tcDateList = tcList.stream().sorted((o1, o2) -> {
                try {
                    DateTime date1 = DateUtil.parse(o1.getTime(), "yyyy-MM-dd HH:mm:ss.SSS");
                    DateTime date2 = DateUtil.parse(o2.getTime(), "yyyy-MM-dd HH:mm:ss.SSS");
                    return date1.compareTo(date2);
                } catch (Exception e) {
                    e.printStackTrace();
                    try {
                        faultReportService.faultReport(ModuleEnum.SJCL.getCode(), ModuleEnum.SHZD.getMsg(),"特征分析填充异常","填充调用算法异常");
                    } catch (UnknownHostException ex) {
                        throw new RuntimeException(ex);
                    }
                    return 0;
                }
            }).collect(Collectors.toList());
            if (CollUtil.isNotEmpty(tcDateList)) {
                tcDateList.forEach((x) -> {
                    Map<String, Object> map = new HashMap<>(2);
                    if (x.getTime().length() == HealthManagerConstant.TIME_TWENTY_TWO) {
                        map.put("time", x.getTime() + "0");
                    } else {
                        map.put("time", x.getTime());
                    }
                    map.put("value", x.getValue());
                    tcBackDataList.add(map);
                });
            }
        }

        // 平滑后
        List<TelemetryData> phList = telemetryDataService.getPhList(dataFeatureDto);
        if(!CollectionUtils.isEmpty(phList)){
            List<TelemetryData> phDateList = phList.stream().sorted((o1, o2) -> {
                try {
                    DateTime date1 = DateUtil.parse(o1.getTime(), "yyyy-MM-dd HH:mm:ss.SSS");
                    DateTime date2 = DateUtil.parse(o2.getTime(), "yyyy-MM-dd HH:mm:ss.SSS");
                    return date1.compareTo(date2);
                } catch (Exception e) {
                    e.printStackTrace();
                    try {
                        faultReportService.faultReport(ModuleEnum.SJCL.getCode(), ModuleEnum.SHZD.getMsg(),"特征分析平滑异常","平滑调用算法异常");
                    } catch (UnknownHostException ex) {
                        throw new RuntimeException(ex);
                    }
                    return 0;
                }
            }).collect(Collectors.toList());
            if (CollUtil.isNotEmpty(phDateList)) {
                phDateList.forEach((x) -> {
                    Map<String, Object> map = new HashMap<>(2);
                    if (x.getTime().length() == HealthManagerConstant.TIME_TWENTY_TWO) {
                        map.put("time", x.getTime() + "0");
                    } else {
                        map.put("time", x.getTime());
                    }
                    map.put("value", x.getValue());
                    phBackDataList.add(map);
                });
            }

        }

        // 原始数据
        List<TelemetryData> ycList = telemetryDataService.getYcList(dataFeatureDto);
        List<TelemetryData> ycDateList = ycList.stream().sorted((o1, o2) -> {
            try {
                DateTime date1 = DateUtil.parse(o1.getTime(), "yyyy-MM-dd HH:mm:ss.SSS");
                DateTime date2 = DateUtil.parse(o2.getTime(), "yyyy-MM-dd HH:mm:ss.SSS");
                return date1.compareTo(date2);
            } catch (Exception e) {
                e.printStackTrace();
                try {
                    faultReportService.faultReport(ModuleEnum.SJCL.getCode(), ModuleEnum.SHZD.getMsg(),"特征分析原始数据异常","原始数据异常");
                } catch (UnknownHostException ex) {
                    throw new RuntimeException(ex);
                }
                return 0;
            }
        }).collect(Collectors.toList());

        if (CollUtil.isNotEmpty(ycDateList)) {
            ycDateList.forEach((x) -> {
                Map<String, Object> map = new HashMap<>(2);
                map.put("time", x.getTime());
                map.put("value", x.getValue());
                ycDataList.add(map);
            });
        }
        // 野值
        dataFeatureDto.setValueType("2");
        List<TelemetryData> tiYeList = telemetryDataService.getTyList(dataFeatureDto);
        if(!CollectionUtils.isEmpty(tiYeList)){
            List<TelemetryData> tiYeDateList = tiYeList.stream().sorted((o1, o2) -> {
                try {
                    DateTime date1 = DateUtil.parse(o1.getTime(), "yyyy-MM-dd HH:mm:ss.SSS");
                    DateTime date2 = DateUtil.parse(o2.getTime(), "yyyy-MM-dd HH:mm:ss.SSS");
                    return date1.compareTo(date2);
                } catch (Exception e) {
                    e.printStackTrace();
                    try {
                        faultReportService.faultReport(ModuleEnum.SJCL.getCode(), ModuleEnum.SHZD.getMsg(),"特征分析野值异常","野值调用算法异常");
                    } catch (UnknownHostException ex) {
                        throw new RuntimeException(ex);
                    }
                    return 0;
                }
            }).collect(Collectors.toList());
            if (CollUtil.isNotEmpty(tiYeDateList)) {
                tiYeDateList.forEach((x) -> {
                    Map<String, Object> map = new HashMap<>(2);
                    if (x.getTime().length() == HealthManagerConstant.TIME_TWENTY_TWO) {
                        map.put("time", x.getTime() + "0");
                    } else {
                        map.put("time", x.getTime());
                    }
                    map.put("value", x.getValue());
                    yzDataList.add(map);
                });
            }

        }

        // 填充值
        dataFeatureDto.setValueType("2");
        List<TelemetryData> tianChongList = telemetryDataService.getTcList(dataFeatureDto);
        if(!CollectionUtils.isEmpty(tianChongList)){
            List<TelemetryData> tianChongDateList = tianChongList.stream().sorted((o1, o2) -> {
                try {
                    DateTime date1 = DateUtil.parse(o1.getTime(), "yyyy-MM-dd HH:mm:ss.SSS");
                    DateTime date2 = DateUtil.parse(o2.getTime(), "yyyy-MM-dd HH:mm:ss.SSS");
                    return date1.compareTo(date2);
                } catch (Exception e) {
                    e.printStackTrace();
                    try {
                        faultReportService.faultReport(ModuleEnum.SJCL.getCode(), ModuleEnum.SHZD.getMsg(),"特征分析填充值异常","填充值调用算法异常");
                    } catch (UnknownHostException ex) {
                        throw new RuntimeException(ex);
                    }
                    return 0;
                }
            }).collect(Collectors.toList());
            if (CollUtil.isNotEmpty(tianChongDateList)) {
                tianChongDateList.forEach((x) -> {
                    Map<String, Object> map = new HashMap<>(2);
                    if (x.getTime().length() == HealthManagerConstant.TIME_TWENTY_TWO) {
                        map.put("time", x.getTime() + "0");
                    } else {
                        map.put("time", x.getTime());
                    }
                    map.put("value", x.getValue());
                    tcDataList.add(map);
                });
            }

        }

        // 中位数
        Map<String, Object> finalMap = new HashMap<>(8);
        DataMiddle dataMiddle = dataMiddleService
                .selectOne(DataMiddle.builder().taskId(dataFeatureDto.getTaskId()).paramCode(dataFeatureDto.getParamCode())
                        .startTime(dataFeatureDto.getStartTime()).endTime(dataFeatureDto.getEndTime()).build());
        if (BeanUtil.isNotEmpty(dataMiddle)) {
            finalMap.put("middleData", dataMiddle);
        }


        //补数据
//        List<String> xlist=new ArrayList<>();
//        List<Map<String, Object>> ycDataList2 = CollUtil.newArrayList();
//        List<Map<String, Object>> phBackDataList2 = CollUtil.newArrayList();
//        List<Map<String, Object>> tcBackDataList2 = CollUtil.newArrayList();
//        List<Map<String, Object>> tyBackDataList2 = CollUtil.newArrayList();
//        if (!CollectionUtils.isEmpty(ycDataList)) {
//            ycDataList2 = DataFeatureServiceImpl.addDataList(ycDataList);
//            for(Object obj:ycDataList2){
//                Map<String, Object> oneMap = (Map<String, Object>) obj;
//                xlist.add(oneMap.get("time").toString());
//            }
//            xlist=xlist.stream().distinct().sorted().collect(Collectors.toList());
//        }
//        if (!CollectionUtils.isEmpty(ycDataList2)) {
//            ycDataList2 = DataFeatureServiceImpl.addNullValue(xlist, ycDataList2);
//        }
//
//        if (!CollectionUtils.isEmpty(phList)) {
//            phBackDataList2 = DataFeatureServiceImpl.addNullValue(xlist, phBackDataList);
//        }
//        if (!CollectionUtils.isEmpty(tyList)) {
//            tyBackDataList2 = DataFeatureServiceImpl.addNullValue(xlist, tyBackDataList);
//        }
//        if (!CollectionUtils.isEmpty(tcList)) {
//            tcBackDataList2 = DataFeatureServiceImpl.addNullValue(xlist, tcBackDataList);
//        }

//        finalMap.put("tyBackData", tyBackDataList2);
//        finalMap.put("tcBackData", tcBackDataList2);
//        finalMap.put("phBackData", phBackDataList2);
//
//        if (!CollectionUtils.isEmpty(ycDataList2)) {
//            finalMap.put("ycData", ycDataList2);
//        } else {
//            finalMap.put("ycData", ycDataList);
//        }

        finalMap.put("tyBackData", tyBackDataList);
        finalMap.put("tcBackData", tcBackDataList);
        finalMap.put("phBackData", phBackDataList);
        finalMap.put("ycData", ycDataList);
        finalMap.put("yzData", yzDataList);
        finalMap.put("tcData", tcDataList);
        finalMap.put("paramCode", dataFeatureDto.getParamCode());
        return CheckResult.success(finalMap);
    }

    /**
     * 执行sql指定数据源
     *
     * @return CheckResult<Object>
     */
    @Override
    public CheckResult<Object> excuteRunSql(DataSourceVo dataSourceVo) {
        if (dsParam.getDsApiOrDb()) {
            HttpResponse postResponse = HttpUtil.createRequest(Method.POST, dsParam.getGetRunSql()).timeout(600000)
                    .body(JSON.toJSONString(dataSourceVo)).execute();
            if (postResponse.getStatus() != HttpStatus.HTTP_OK) {
                throw new HealthException("接口调用异常");
            }
            return CheckResult.success(JSON.parseObject(postResponse.body(), Map.class));
        } else {
            HashMap<String, Object> map = new HashMap<>(2);
            List<Map<String, Object>> objectList = appTlmCheckAnomalRsltMapper.selectAppTlmCheckData(dataSourceVo);
            map.put("data", objectList);
            return CheckResult.success(map);
        }
    }

    /**
     * 根据sql查询pg库数据
     *
     * @param sql sql语句
     * @return List<DiagnoseMultipleParametersData>
     */
    @Override
    public List<DiagnoseMultipleParametersData> getClickHouseBySql(String sql) {
        return appTlmCheckAnomalRsltMapper.getClickHouseBySql(sql);
    }

    /**
     * 获取质量分析报告
     *
     * @param reportVo 质量分析报告入参
     * @return DataQualityReport
     */
    @Override
    public DataQualityReport getReportInfos(ReportVo reportVo) {
        //输入开始结束时间
        if (StrUtil.isNotEmpty(reportVo.getStartTime()) && StrUtil.isNotEmpty(reportVo.getEndTime())) {
            DataQualityReport dataQualityReport = new DataQualityReport();
            //统计中断次数
            Integer zdTotal1 = countMethod("app_tlm_check_frameloss_rslt", "zdtotal", reportVo, "2");
            int zdInt;
            if (zdTotal1 == null) {
                zdInt = 0;
                dataQualityReport.setZdTotal(0);
            } else {
                zdInt = zdTotal1;
                dataQualityReport.setZdTotal(zdTotal1);
            }
            //   统计丢帧次数
            Integer dzTotal1 = countMethod("app_tlm_check_frameloss_rslt", "dztotal", reportVo, "3");
            int dzInt;
            if (dzTotal1 == null) {
                dzInt = 0;
                dataQualityReport.setDzTotal(0);
            } else {
                dzInt = dzTotal1;
                dataQualityReport.setDzTotal(dzTotal1);
            }
            //统计复帧次数
            Integer fzTotal1 = countMethod("app_tlm_check_anomal_rslt", "fztotal", reportVo, "4");
            int fzInt;
            if (fzTotal1 == null) {
                fzInt = 0;
                dataQualityReport.setFzTotal(0);
            } else {
                fzInt = fzTotal1;
                dataQualityReport.setFzTotal(fzTotal1);
            }
            //统计识别字次数
            Integer sbzTotal1 = countMethod("app_tlm_check_anomal_rslt", "sbztotal", reportVo, "1");
            int sbzInt;
            if (sbzTotal1 == null) {
                sbzInt = 0;
                dataQualityReport.setSbzTotal(0);
            } else {
                sbzInt = sbzTotal1;
                dataQualityReport.setSbzTotal(sbzTotal1);
            }
            dataQualityReport.setSatelliteId(Long.parseLong(reportVo.getSatelliteId()));
            dataQualityReport.setSatelliteCode(reportVo.getSatelliteCode());
            dataQualityReport.setSatelliteName(reportVo.getSatelliteName());
            dataQualityReport.setCreateTime(DateUtil.parse(reportVo.getStartTime()));
            dataQualityReport.setUpdateTime(DateUtil.parse(reportVo.getEndTime()));
            dataQualityReport.setTotal(zdInt + dzInt + fzInt + sbzInt);
            return dataQualityReport;

        } else {
            //不输入时间默认查询数据最小时间到当前时间
            DataQualityReport dataQualityReport = new DataQualityReport();
            //获取数据的最小时间
            DateTime minTime = minTime("app_tlm_check_anomal_rslt", "app_tlm_check_frameloss_rslt", "minTime", reportVo);
            if (minTime == null) {
                dataQualityReport.setCreateTime(new Date());
            } else {
                dataQualityReport.setCreateTime(minTime);
            }

            //统计中断次数
            Integer zdTotal = countMethod("app_tlm_check_frameloss_rslt", "zdtotal", reportVo, "2");
            int zdInt;
            if (zdTotal == null) {
                zdInt = 0;
                dataQualityReport.setZdTotal(0);
            } else {
                zdInt = zdTotal;
                dataQualityReport.setZdTotal(zdTotal);
            }
            //统计丢帧次数
            Integer dzTotal = countMethod("app_tlm_check_frameloss_rslt", "dztotal", reportVo, "3");
            int dzInt;
            if (dzTotal == null) {
                dzInt = 0;
                dataQualityReport.setDzTotal(0);
            } else {
                dzInt = dzTotal;
                dataQualityReport.setDzTotal(dzTotal);
            }
            //统计复帧次数
            Integer fzTotal = countMethod("app_tlm_check_anomal_rslt", "fztotal", reportVo, "4");
            int fzInt;
            if (fzTotal == null) {
                fzInt = 0;
                dataQualityReport.setFzTotal(0);
            } else {
                fzInt = fzTotal;
                dataQualityReport.setFzTotal(fzTotal);
            }
            //统计识别字 次数
            Integer sbzTotal = countMethod("app_tlm_check_anomal_rslt", "sbztotal", reportVo, "1");
            int sbzInt;
            if (sbzTotal == null) {
                sbzInt = 0;
                dataQualityReport.setSbzTotal(0);
            } else {
                sbzInt = sbzTotal;
                dataQualityReport.setSbzTotal(sbzTotal);
            }

            dataQualityReport.setSatelliteId(Long.parseLong(reportVo.getSatelliteId()));
            dataQualityReport.setSatelliteCode(reportVo.getSatelliteCode());
            dataQualityReport.setSatelliteName(reportVo.getSatelliteName());
            dataQualityReport.setUpdateTime(new Date());
            dataQualityReport.setTotal(zdInt + dzInt + fzInt + sbzInt);

            return dataQualityReport;
        }

    }

    /**
     * @param tableName   表名
     * @param countAlias  统计类型别名
     * @param requireType 区分是中断还是丢帧，复诊，识别字
     */
    public Integer countMethod(String tableName, String countAlias, ReportVo reportVo, String requireType) {

        DataSourceVo anomalData = new DataSourceVo();
        anomalData.setDbKey("HOLOGRES");
        if (StrUtil.isNotEmpty(requireType)) {
            if (StrUtil.isNotEmpty(reportVo.getStartTime()) && StrUtil.isNotEmpty(reportVo.getEndTime())) {
                anomalData.setSql("select count(*) as " + countAlias + " from " + tableName + " where " + "anomal_cd = '" + Integer.parseInt(requireType) + "' and satellite_code  = '" + reportVo.getSatelliteCode() + "'  and Data_Time between '" + reportVo.getStartTime() + "' and '" + reportVo.getEndTime() + "'");

            } else {
                anomalData.setSql("select count(*) as " + countAlias + " from " + tableName + " where " + "anomal_cd = '" + Integer.parseInt(requireType) + "' and satellite_code  = '" + reportVo.getSatelliteCode() + "'");
            }
        } else {
            anomalData.setSql("select count(*) as " + countAlias + " from " + tableName + " where " + " satellite_code  = '" + reportVo.getSatelliteCode() + "'");
        }
        CheckResult<Object> result = dataQualityService.excuteRunSql(anomalData);
        Map commonData = (Map) result.getData();
        String commonDataStr = JSONObject.toJSONString(commonData.get("data"));
        Integer commonTotal = null;
        if (!HealthManagerConstant.NULL_STR.equals(commonDataStr)) {
            List<Map> mapList = JSONObject.parseArray(commonDataStr, Map.class);
            Map tatalMap = mapList.get(0);
            commonTotal = (Integer) tatalMap.get(countAlias);
        }
        return commonTotal;
    }

    /**
     * 获取质量分析最小时间
     *
     * @param anomalTableName    中断表名
     * @param frameLossTableName 丢帧表名
     * @param countAlias         count别名
     * @param reportVo           入参
     * @return DateTime
     */
    public DateTime minTime(String anomalTableName, String frameLossTableName, String countAlias, ReportVo reportVo) {
        DateTime min = null;
        DataSourceVo anomaDateTime = new DataSourceVo();
        anomaDateTime.setDbKey("HOLOGRES");
        anomaDateTime.setSql("select min(Data_Time) as " + countAlias + " from " + anomalTableName + "   where  satellite_code =  '" + reportVo.getSatelliteCode() + "'");
        CheckResult<Object> checkResult = null;
        checkResult = dataQualityService.excuteRunSql(anomaDateTime);
        Map anomal = (Map) checkResult.getData();
        List<Object> minTimeList = (List) anomal.get("data");
        DateTime time = null;
        if (CollectionUtil.isNotEmpty(minTimeList)) {
            Map minTime = (Map) minTimeList.get(0);
            if (MapUtil.isNotEmpty(minTime)) {
                if (minTime.get("minTime") != null) {
                    time = DateUtil.parse(minTime.get("minTime").toString());
                }

            }
        }

        DataSourceVo framelossData = new DataSourceVo();
        framelossData.setDbKey("HOLOGRES");
        framelossData.setSql("select min(Data_Time) as " + countAlias + " from " + frameLossTableName + " where  satellite_code  = '" + reportVo.getSatelliteCode() + "'");
        CheckResult<Object> checkResultFrameloss = null;
        checkResultFrameloss = dataQualityService.excuteRunSql(framelossData);
        Map framelossData1 = (Map) checkResultFrameloss.getData();
        List<Object> frameMinTimeList = (List) framelossData1.get("data");
        DateTime framelossTime = null;
        if (CollectionUtil.isNotEmpty(frameMinTimeList)) {
            Map frameMinTime = (Map) frameMinTimeList.get(0);
            if (MapUtil.isNotEmpty(frameMinTime)) {
                if (frameMinTime.get("minTime") != null) {
                    framelossTime = DateUtil.parse(frameMinTime.get("minTime").toString());
                }
            }
        }

        if (CollectionUtil.isEmpty(minTimeList)) {
            min = framelossTime;
        }

        if (CollectionUtil.isEmpty(frameMinTimeList)) {
            min = time;
        }

        if (CollectionUtil.isEmpty(minTimeList) && CollectionUtil.isEmpty(frameMinTimeList)) {
            min = new DateTime();
        }
        if (CollectionUtil.isNotEmpty(minTimeList) && CollectionUtil.isNotEmpty(frameMinTimeList)) {
            int compare = DateUtil.compare(time, framelossTime);
            if (time != null || framelossTime != null) {
                if (compare == 0) {
                    min = framelossTime;
                } else if (compare < 0) {
                    min = time;
                } else if (compare > 0) {
                    min = framelossTime;
                }
            } else {
                min = new DateTime();
            }
        }
        return min;
    }

    /**
     * 根据卫星代号获取质量分析数据
     *
     * @param reportVo 分析入参
     * @return 结果日志
     */
    @Override
    public PageInfo<QualityVo> getQualityBySatelliteCode(ReportVo reportVo) {
        List<QualityVo> finalList = new ArrayList<>();
        DataSourceVo framelossData = new DataSourceVo();
        framelossData.setDbKey("HOLOGRES");
        CheckResult<Object> checkResult1 = null;
        framelossData.setSql("select *  from app_tlm_check_frameloss_rslt where satellite_code  = '" + reportVo.getSatelliteCode() + "'" + " limit " + reportVo.getSize() + " offset " + (reportVo.getPage() - 1));
        checkResult1 = dataQualityService.excuteRunSql(framelossData);
        Map data1 = (Map) checkResult1.getData();
        String frameDataString = JSON.toJSONString(data1.get("data"));
        List<QualityVo> framelist = JSONObject.parseArray(frameDataString, QualityVo.class);
        for (QualityVo frame : framelist) {
            finalList.add(frame);
        }

        DataSourceVo anomalData = new DataSourceVo();
        anomalData.setDbKey("HOLOGRES");
        CheckResult<Object> result = null;
        anomalData.setSql("select *  from app_tlm_check_anomal_rslt where satellite_code  = '" + reportVo.getSatelliteCode() + "'" + " limit " + reportVo.getSize() + " offset " + (reportVo.getPage() - 1));
        result = dataQualityService.excuteRunSql(anomalData);
        Map anomalData1 = (Map) result.getData();
        String anomalDataString = JSON.toJSONString(anomalData1.get("data"));
        List<QualityVo> anomallist = JSONObject.parseArray(anomalDataString, QualityVo.class);

        for (QualityVo anomalVo : anomallist) {
            finalList.add(anomalVo);
        }

        Integer frameTotal = countMethod("app_tlm_check_frameloss_rslt", "frametotal", reportVo, "");
        int frameTotal1;
        if (frameTotal == null) {
            frameTotal1 = 0;
        } else {
            frameTotal1 = frameTotal;
        }

        Integer anomalTotal = countMethod("app_tlm_check_anomal_rslt", "anomaltotal", reportVo, "");
        int anomalTotal1;
        if (anomalTotal == null) {
            anomalTotal1 = 0;
        } else {
            anomalTotal1 = anomalTotal;
        }

        PageInfo<QualityVo> info = new PageInfo<>();
        info.setList(finalList);
        info.setTotal(frameTotal1 + anomalTotal1);
        info.setPages((reportVo.getPage() - 1));
        info.setSize(reportVo.getSize());
        return info;
    }
}
